<script>
export default {
  name: "shoppingCart",
  data(){
    return {
      list:[
        {id:1,str:"房子",price:10},{id:2,str:"车子",price:5}
      ],
      lumpSum:0,
      flag:true
    }
  },
  computed(){

  },
  methods:{
    add(){
      this.flag = !this.flag
      if(this.flag === true){
        this.lumpSum = this.list[0].price
      }else {
        this.lumpSum =  this.lumpSum - this.list[0].price
      }
      // this.lumpSum = this.list[0].price
      // this.lumpSum = this.list[1].price
      console.log(this.lumpSum)
    }
  }
}
</script>

<template>
 <div>
   <div v-for="item in list" :key="item.id">
     <input type="checkbox" @click="add" :checked="!flag">{{item.str}}{{item.price}}
   </div>
   <div>
     总计：{{lumpSum}}
   </div>
 </div>
</template>

<style scoped lang="less">

</style>